﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using BudgetManager.Domain;
using System.Collections.ObjectModel;
using System.Windows.Controls.DataVisualization.Charting;

namespace BudgetManager
{
    public partial class Home : PhoneApplicationPage
    {

        
         ObservableCollection<KeyValuePair<String,double>> expensesList;
         ObservableCollection<KeyValuePair<String, double>> incomesList;
         ObservableCollection<KeyValuePair<string, double>> difList;

        public Home()
        {
            InitializeComponent();

            txtBlockBalance.Text = AccountManager.SelectedAccount.GetCurrentBalance().ToString()+" €";

            txtBlockMonthExpense.Text = AccountManager.SelectedAccount.GetMonthExpenses().ToString() + " €";
            txtBlockMonthIncome.Text = AccountManager.SelectedAccount.GetMonthIncomes().ToString() + " €";

            txtBlockTotalExpenses.Text = AccountManager.SelectedAccount.GetTotalExpenses().ToString() + " €";
            txtBlockTotalIncomes.Text = AccountManager.SelectedAccount.GetTotalIncomes().ToString() + " €";
            
           
            showColumnChart();
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Random random = new Random(DateTime.Now.Millisecond);
            Color color = Color.FromArgb(255, (byte)random.Next(255), (byte)random.Next(255), (byte)random.Next(255));
            return new SolidColorBrush(color);
        }

        private void showColumnChart()

        {
            incomesList = new ObservableCollection<KeyValuePair<string, double>>();
            expensesList = new ObservableCollection<KeyValuePair<string, double>>();
            difList = new ObservableCollection<KeyValuePair<string, double>>();

            incomesList.Add(new KeyValuePair<string,double>("Expenses",AccountManager.SelectedAccount.GetTotalExpenses()));
            expensesList.Add(new KeyValuePair<string,double>("Incomes",AccountManager.SelectedAccount.GetTotalIncomes()));

            double dif = AccountManager.SelectedAccount.GetCurrentBalance();

            difList.Add(new KeyValuePair<string,double>("Available" , dif));

            ((ColumnSeries)ExsAndInc.Series[0]).ItemsSource = incomesList;
            ((ColumnSeries)ExsAndInc.Series[1]).ItemsSource = expensesList;
            ((ColumnSeries)ExsAndInc.Series[2]).ItemsSource =difList; 
            
           

            
        }
        
      
        private void ontapExpenses(object sender, System.Windows.Input.GestureEventArgs e)
        {

            NavigationService.Navigate(new Uri(string.Format("/Expense.xaml?"), UriKind.Relative));

        }
        private void onTapIncomes(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/Income.xaml?"), UriKind.Relative));
        }
        private void ontapGoals(object sender, System.Windows.Input.GestureEventArgs e)
        {

            NavigationService.Navigate(new Uri(string.Format("/Goal.xaml?"), UriKind.Relative));

        }
        private void ontapStats(object sender, System.Windows.Input.GestureEventArgs e)
        {

            NavigationService.Navigate(new Uri(string.Format("/Stats.xaml?"), UriKind.Relative));

        }
        private void ontapsettings(object sender, System.Windows.Input.GestureEventArgs e)
        {

            NavigationService.Navigate(new Uri(string.Format("/Settings.xaml?"), UriKind.Relative));

        }
        

     
       /* protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;  //Cancels the default behavior.
        }*/

        private void ontapAlerts(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format("/Alerts.xaml?"), UriKind.Relative));
        }
    }
}